package com.heima.feigns.fallback;

import com.heima.feigns.AuthorFeign;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author lo
 * @date 2021/9/21
 */
@Component
@Slf4j
public class AuthorFeignFallback implements FallbackFactory<AuthorFeign> {
    @Override
    public AuthorFeign create(Throwable throwable) {
        return  new AuthorFeign() {
            @Override
            public ResponseResult findByUserId(Integer userId) {
                log.error("参数: {}",userId);
                log.error("作者 findByUserId 远程调用出错啦 ~~~ !!!! {} ",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
            }

            @Override
            public ResponseResult save(ApAuthor apAuthor) {

                log.error("参数: {}",apAuthor);
                log.error("作者 save 远程调用出错啦 ~~~ !!!! {} ",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
            }
        };
    }
}
